﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;
using PPIDesktopClient.General;
using PPIProxy;
using VMind.Global;
using PPIMobileInterface;

namespace PPIDesktopClient.Logic
{
    public class LUtility
    {
        public static List<EUtility> SelectAllIdName()
        {
            ConfigReader _Reader = ConfigReader.GetInstance();
            List<EUtility> _UtilityList = new List<EUtility>();
            EUtility _Utility;

            DataSet ds = WUtility.SelectAllIdName(_Reader.GetConnectionString());

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                _Utility = new EUtility();
                _Utility.UtilityId = ConvertHelper.ToInt32(dr["UtilityId"]);
                _Utility.Name = ConvertHelper.Tostring(dr["Name"]);
                _UtilityList.Add(_Utility);
            }
            return _UtilityList;
        }

        #region Mobile

        public static void InsertUtilities(string connectionString)
        {
            List<EUtility> _utilities = SelectAllIdName();
            StringBuilder _query = new StringBuilder();
            foreach (EUtility e in _utilities)
            {
                _query.AppendLine("insert into tb_Utility values (" + e.UtilityId + ",'" + e.Name + "')");
            }
            Utils.InsertUtilities(connectionString, _query.ToString());
        }

        #endregion
    }
}
